package com.jch.Dao;

import com.entity.Movie;
import com.entity.Studios;
import com.entity.User;

import java.sql.SQLException;
import java.util.List;

public class StudiosDao extends BaseDao {
    public List<Studios> queryStudios(Object...params){
        String sql="SELECT * FROM `ticket` t, studios s where t.sid = s.sid and t.uid =? ORDER BY  uid DESC LIMIT 9;";
        return findList(Studios.class,sql,params);
    }

    public List<Studios> queryStudiosByCinemaName(Object...params){
        String sql="select * from studios where sCinemaName=?";
        return findList(Studios.class,sql,params);
    }

//    public Studios queryStudios(Object...params){
//        String sql="select * from studios where sid=?";
//
//        return findBean(Studios.class,sql);
//
//    }
    public List<Studios> queryStudiosById(Object...params) {
        String sql = "select * from user where uName = ? and uPass = ? ";
        try {
            return queryForListObject(sql, Studios.class, params);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 根据实体类数据更新用户
     *
     * @param studios
     * @return
     */
    public int updateStudios(Studios studios) {
        String sql = "update studios set sHallName =?,sCinemaAddress=?,sMovieTitle=?,sstartTime=?,sPrice=?" +
                ",ssurplus=?,sCinemaName=?  where sid=?";
        Object[] params = {studios.getsHallName(),studios.getsCinemaAddress(),studios.getsMovieTitle()
                ,studios.getSstartTime(),studios.getsPrice(),studios.getSsurplus()
                ,studios.getsCinemaName(),studios.getSid()};
        return update(sql, params);
    }
    /**
     * 根据id删除一条数据
     *
     * @param id
     * @return
     */
    public int deleteStudios(int id) {
        String sql = "delete from studios where sid=?";
        Object[] params = {id};
        return update(sql, params);
    }

    /**
     * 根据用户对象增加一条数据
     *
     //     * @param studios
     * @return
     */
    public int insertStudios(Studios studios) {
        String sql = "insert into studios values(null,?,?,?,?,?,?,?)";
        Object[] params = {studios.getsHallName(),studios.getsCinemaAddress(),studios.getsMovieTitle()
                ,studios.getSstartTime(),studios.getsPrice(),studios.getSsurplus()
                ,studios.getsCinemaName()};
        return update(sql, params);
    }







    public static void main(String[] args) {
        StudiosDao studiosDao = new StudiosDao();
//        List<User> users = userDao.queryUsersById("admin", "admin");
//        for (User user : users) {
//            System.out.println(user);
//        }
//         int i = userDao.InsertValues("xg", "123", 0);
//        System.out.println("插入了"+i+"条数据");

//        int i = userDao.updateAddBalance(150,"zxx");
//        System.out.println("更新了"+i+"条数据");

//        int i = userDao.updateReduceBalance(150,"zxx");
//        System.out.println("更新了"+i+"条数据");

//        List<User> users = userDao.queryUserByBalance("zxx");
//        for (User user : users) {
//            System.out.println(user);
//        }


    }
}